using Jaws.Core.Web.Entities;
using Jaws.Core.Web.Entities.Pages;
using Jaws.Core.Web.Entities.Post;
using Jaws.Core.Web.Entities.Roles;
using Jaws.Core.Web.Entities.SiteSettings;

namespace Jaws.Core.Web.Data
{
    public static class Singletons
    {
        private static PageCollection _pages;
        private static PostCollection _posts;
        private static RoleCollection _roles;
        private static SiteSettingCollection _siteSettingsCollection;
        private static SiteSettings _siteSettings;
        
        public static PageCollection Singleton(this PageCollection pageCollection)
        {
            if (_pages == null)
            {
                _pages = XmlCollectionBase<PageCollection, Page>.Load();
            }
            return _pages;
        }

        public static PostCollection Singleton(this PostCollection postCollection)
        {
            if (_posts == null)
            {
                _posts = XmlCollectionBase<PostCollection, Post>.Load();
            }
            return _posts;
        }

        public static RoleCollection Singleton(this RoleCollection roleCollection)
        {
            if (_roles == null)
            {
                _roles = XmlCollectionBase<RoleCollection, Role>.Load();
            }
            return _roles;
        }

        public static SiteSettingCollection Singleton(this SiteSettingCollection siteSettings)
        {
            if (_siteSettingsCollection == null)
            {
                _siteSettingsCollection = XmlCollectionBase<SiteSettingCollection, SiteSettings>.Load();
            }
            return _siteSettingsCollection;
        }

        public static SiteSettings Singleton(this SiteSettings siteSettings)
        {
            if (_siteSettings == null)
            {
                _siteSettings = XmlCollectionBase<SiteSettingCollection, SiteSettings>.Load()[0];
            }
            return _siteSettings;
        }


    }
}
